package com.nullpointer.xchatfinal.utils;

import java.util.Calendar;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

import com.google.android.gms.games.internal.notification.GameNotification;
import com.nullpointer.xchatfinal.service.AppNotification;

public class AppNotificationManager {
	private static AppNotificationManager mGameNotificationManager;
	private Context mContext;
	public final static String NOTIFICATION_MESSAGE = "NOTIFICATION_MESSAGE";
	public final static String NAME_CLASS = "NAME_CLASS";
	public final static int SENDER_REQUEST_CODE = 4001;

	public AppNotificationManager(Context context) {
		mContext = context;
	}

	public static AppNotificationManager getInstance(Context context) {
		if (mGameNotificationManager == null) {
			mGameNotificationManager = new AppNotificationManager(context);
		}
		return mGameNotificationManager;
	}

	public void setUp(int hour, String message) {
		int timeToRepeat = 60 * 1000 * 60 * hour;
		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.MILLISECOND, timeToRepeat);
		Intent intent = new Intent(mContext, AppNotification.class);
		intent.putExtra(NOTIFICATION_MESSAGE, message);
		intent.putExtra(NAME_CLASS, mContext.getClass().getSimpleName());
		PendingIntent sender = PendingIntent.getBroadcast(mContext,
				SENDER_REQUEST_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT);

		AlarmManager alarmManager = (AlarmManager) mContext
				.getSystemService(Context.ALARM_SERVICE);
		alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
				calendar.getTimeInMillis(), timeToRepeat, sender);
	}
}
